#include<iostream>
using namespace std;

//父类抽象类
class CPU
{
    public:
        virtual void calculate() = 0;
};

class VideoCard
{
    public:
        virtual void display() = 0;
};

class Memory
{
    public:
        virtual void storage()=0;
};

//组装电脑
class Computer
{
    public:
        // 有点类似python中的def __init__()函数。叫做构造函数。
        Computer( CPU * cpu,VideoCard * vc,Memory *mem)
        {
             m_cpu = cpu;
             m_vc=vc;
            m_mem=mem;
            
        }

        //提供一个工作的函数
        void doWork()
        {
            m_cpu->calculate();
            m_vc->display();
            m_mem->storage();
        }

        ~Computer()
        {
            if (m_cpu != NULL)
            {
                delete m_cpu;
                m_cpu = NULL;
            }
            if (m_vc != NULL)
            {
                delete m_vc;
                m_vc = NULL;
            }

            if (m_mem != NULL)
            {
                delete m_mem;
                m_mem = NULL;
            }
        }


    private:
        CPU * m_cpu;
        VideoCard * m_vc;
        Memory *m_mem;

};

//继承后，在具体实现硬件厂商
class InterCPU:public CPU
{
    public:
        virtual void calculate()
        {
            cout<<"Inter的CPU开始计算了!"<<endl;
        }
};

class  InterVideoCard:public VideoCard
{
    public:
        virtual void display()
        {
            cout<<"Inter的显卡开始显示了!"<<endl;
        }
};

class  InterMemory:public Memory
{
    public:
        virtual void storage()
        {
            cout<<"Inter的内存开始存储了!"<<endl;
        }
};


void test01()
{
    CPU *interCPU = new InterCPU;
    VideoCard * interVideoCard =new InterVideoCard;
    Memory *interMemory = new InterMemory;

    Computer * inter_computer = new Computer(interCPU,interVideoCard,interMemory);
    inter_computer->doWork();
    //手动释放堆区内存，但是 CPU *interCPU， VideoCard * interVideoCard ， Memory *interMemory 还没有释放，需要创建析构函数释放。
    delete inter_computer;
   
}

int main04(int argc, char const *argv[])
{
    test01();

    return 0;
}
